package map_;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author 小闽
 * @Date 2024/11/13 21:33
 * @PackageName: map_
 * @ClassName: MapMethod
 * @Description:
 * @Version
 */
@SuppressWarnings({"all"})
public class MapMethod {
    public static void main(String[] args) {
        Map map = new HashMap();
        map.put("邓超",new Book("",100));
        map.put("邓超","孙俪");
        map.put("王宝强","马蓉");
        map.put("宋洁","马蓉");
        map.put("马蓉",null);
        map.put(null,"马蓉");
        map.put(null,"刘亦菲");
        map.put("鹿晗","关晓彤");

        System.out.println("map=" + map);

        // remove:根据键删除映射关系
        map.remove(null);
        System.out.println("map=" + map);
        // get：根据键获取值
        Object val = map.get("鹿晗");
        System.out.println("val=" + val);
        // size:获取元素个数
        System.out.println("k-v=" + map.size());
        // isEmpty：判断个数是否为0
        System.out.println(map.isEmpty());
        // clear: 清除k-v
//        map.clear();
//        System.out.println("map=" + map);
        // containsKey：查找键是否存在
        System.out.println("结果=" + map.containsKey("鹿晗"));

    }
}
class Book{
    private String name;
    private int num;

    public Book(String name, int num) {
        this.name = name;
        this.num = num;
    }

    @Override
    public String toString() {
        return "Book{" +
                "name='" + name + '\'' +
                ", num=" + num +
                '}';
    }
}